package com.bracketbird.client.gui.clientchannel;

/**
 *
 */
public class ClientChannel extends Channel {

    public ClientChannel() {
        JSChannelBridge.handler = new JSChannelBridgeHandler() {
            public void messageRecieved(String json) {
                ClientChannel.this.messageRecieved(json);
            }

            public void channelOpened() {
                ClientChannel.this.channelOpened();
            }

            public void channelClosed() {
                ClientChannel.this.channelClosed();
            }

            public void errorRecieved() {
                ClientChannel.this.errorRecieved();
            }
        };

        JSChannelBridge.exportAPI();

        register(new ClientCreateTeamHandler());
    }


    //ensures that gwt module is loaded before exported api is called from java-script.
    public native void openChannel(String token)
    /*-{
          $wnd.openChannel(token);
      }-*/;


    private void errorRecieved() {
        System.out.println("ErrorRecieved");
    }

    private void channelClosed() {
        System.out.println("ChannelClosed");


    }

    private void channelOpened() {
        System.out.println("ChandelOpened");

    }

    private void messageRecieved(String json) {
        System.out.println("Message Recieved: " + json);

    }


}
